package com.horoscope.astrology.zodiac.signs.free.service

import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.horoscope.astrology.zodiac.signs.free.AppSettingManager
import com.horoscope.astrology.zodiac.signs.free.utils.NotificationUtil
import java.util.*

/**
 *  作者    1024
 *  时间    2020/5/28 下午1:36
 *  文件    项目备份
 *  描述    quote本地闹钟，每3小时执行一次，判断是否在下午2点到5点间，展示最新数据到通知
 */

class QuoteWork(private val mContext: Context, private val mParams: WorkerParameters) :
    Worker(mContext, mParams) {

    // 具体执行逻辑
    override fun doWork(): Result {
        //读取是否在浏览状态
        val quoteNow = AppSettingManager.readInt("Quote_Now", 0)
        if (compareCurrentHour() && quoteNow == 0) {
            //推送通知
            NotificationUtil.notifyByAlarmByService(mContext)
        }
        //不在时间段，重置标志位false
//            return Result.retry()
        return Result.success()
    }

    // 判断时间段
    private fun compareCurrentHour(): Boolean {
        val current = Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
        return current == 14 || current == 15 || current == 16
    }

}